from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-30 14:07:13.897424
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 30, Jan, 2021
Time: 14:07:19
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6753
Nobs: 187.000 HQIC: -46.6003
Log likelihood: 2117.97 FPE: 3.07962e-21
AIC: -47.2304 Det(Omega_mle): 1.92697e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.447205 0.140693 3.179 0.001
L1.Burgenland 0.127037 0.074059 1.715 0.086
L1.Kärnten -0.230832 0.060681 -3.804 0.000
L1.Niederösterreich 0.135606 0.169608 0.800 0.424
L1.Oberösterreich 0.217373 0.148184 1.467 0.142
L1.Salzburg 0.195003 0.078556 2.482 0.013
L1.Steiermark 0.096438 0.105843 0.911 0.362
L1.Tirol 0.160951 0.070696 2.277 0.023
L1.Vorarlberg -0.014189 0.064730 -0.219 0.826
L1.Wien -0.120605 0.142333 -0.847 0.397
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.500910 0.178375 2.808 0.005
L1.Burgenland 0.014891 0.093893 0.159 0.874
L1.Kärnten 0.368532 0.076933 4.790 0.000
L1.Niederösterreich 0.114551 0.215033 0.533 0.594
L1.Oberösterreich -0.151368 0.187872 -0.806 0.420
L1.Salzburg 0.192042 0.099595 1.928 0.054
L1.Steiermark 0.240474 0.134191 1.792 0.073
L1.Tirol 0.138086 0.089631 1.541 0.123
L1.Vorarlberg 0.178015 0.082066 2.169 0.030
L1.Wien -0.584081 0.180454 -3.237 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299770 0.063747 4.702 0.000
L1.Burgenland 0.113120 0.033556 3.371 0.001
L1.Kärnten -0.025349 0.027494 -0.922 0.357
L1.Niederösterreich 0.066416 0.076848 0.864 0.387
L1.Oberösterreich 0.287451 0.067141 4.281 0.000
L1.Salzburg 0.006127 0.035593 0.172 0.863
L1.Steiermark -0.022428 0.047957 -0.468 0.640
L1.Tirol 0.093969 0.032032 2.934 0.003
L1.Vorarlberg 0.105928 0.029329 3.612 0.000
L1.Wien 0.080432 0.064491 1.247 0.212
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217943 0.072599 3.002 0.003
L1.Burgenland -0.008894 0.038215 -0.233 0.816
L1.Kärnten 0.022745 0.031312 0.726 0.468
L1.Niederösterreich 0.032105 0.087520 0.367 0.714
L1.Oberösterreich 0.387920 0.076465 5.073 0.000
L1.Salzburg 0.096992 0.040536 2.393 0.017
L1.Steiermark 0.182526 0.054616 3.342 0.001
L1.Tirol 0.041949 0.036480 1.150 0.250
L1.Vorarlberg 0.087942 0.033401 2.633 0.008
L1.Wien -0.063469 0.073446 -0.864 0.387
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.520561 0.144930 3.592 0.000
L1.Burgenland 0.077719 0.076288 1.019 0.308
L1.Kärnten 0.006983 0.062508 0.112 0.911
L1.Niederösterreich -0.010639 0.174715 -0.061 0.951
L1.Oberösterreich 0.153299 0.152646 1.004 0.315
L1.Salzburg 0.057583 0.080921 0.712 0.477
L1.Steiermark 0.110797 0.109030 1.016 0.310
L1.Tirol 0.211996 0.072825 2.911 0.004
L1.Vorarlberg 0.019296 0.066679 0.289 0.772
L1.Wien -0.135862 0.146619 -0.927 0.354
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156805 0.102649 1.528 0.127
L1.Burgenland -0.016915 0.054032 -0.313 0.754
L1.Kärnten -0.014171 0.044272 -0.320 0.749
L1.Niederösterreich 0.125964 0.123744 1.018 0.309
L1.Oberösterreich 0.391806 0.108114 3.624 0.000
L1.Salzburg -0.023869 0.057313 -0.416 0.677
L1.Steiermark -0.032152 0.077222 -0.416 0.677
L1.Tirol 0.189811 0.051580 3.680 0.000
L1.Vorarlberg 0.044174 0.047226 0.935 0.350
L1.Wien 0.185885 0.103845 1.790 0.073
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.227195 0.130844 1.736 0.082
L1.Burgenland 0.086420 0.068874 1.255 0.210
L1.Kärnten -0.045435 0.056432 -0.805 0.421
L1.Niederösterreich -0.021090 0.157734 -0.134 0.894
L1.Oberösterreich -0.108655 0.137810 -0.788 0.430
L1.Salzburg 0.030933 0.073056 0.423 0.672
L1.Steiermark 0.390799 0.098433 3.970 0.000
L1.Tirol 0.495344 0.065747 7.534 0.000
L1.Vorarlberg 0.163808 0.060198 2.721 0.007
L1.Wien -0.217239 0.132369 -1.641 0.101
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.082015 0.159462 0.514 0.607
L1.Burgenland 0.031023 0.083938 0.370 0.712
L1.Kärnten -0.092233 0.068776 -1.341 0.180
L1.Niederösterreich 0.247936 0.192234 1.290 0.197
L1.Oberösterreich -0.000276 0.167952 -0.002 0.999
L1.Salzburg 0.233167 0.089035 2.619 0.009
L1.Steiermark 0.124011 0.119963 1.034 0.301
L1.Tirol 0.072961 0.080127 0.911 0.363
L1.Vorarlberg 0.041822 0.073365 0.570 0.569
L1.Wien 0.267031 0.161321 1.655 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.590212 0.084063 7.021 0.000
L1.Burgenland -0.020579 0.044249 -0.465 0.642
L1.Kärnten -0.002660 0.036256 -0.073 0.942
L1.Niederösterreich -0.038495 0.101339 -0.380 0.704
L1.Oberösterreich 0.285221 0.088539 3.221 0.001
L1.Salzburg 0.017388 0.046936 0.370 0.711
L1.Steiermark 0.013898 0.063240 0.220 0.826
L1.Tirol 0.080118 0.042240 1.897 0.058
L1.Vorarlberg 0.138902 0.038676 3.591 0.000
L1.Wien -0.059565 0.085043 -0.700 0.484
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.152115 0.009767 0.211053 0.254443 0.069985 0.067162 -0.052883 0.173311
Kärnten 0.152115 1.000000 0.020018 0.193939 0.165222 -0.114569 0.170183 0.023957 0.314419
Niederösterreich 0.009767 0.020018 1.000000 0.305899 0.078185 0.215294 0.131118 0.054062 0.369341
Oberösterreich 0.211053 0.193939 0.305899 1.000000 0.297123 0.302940 0.106209 0.081184 0.131759
Salzburg 0.254443 0.165222 0.078185 0.297123 1.000000 0.155235 0.049891 0.084592 -0.017658
Steiermark 0.069985 -0.114569 0.215294 0.302940 0.155235 1.000000 0.108018 0.096454 -0.094982
Tirol 0.067162 0.170183 0.131118 0.106209 0.049891 0.108018 1.000000 0.163873 0.149637
Vorarlberg -0.052883 0.023957 0.054062 0.081184 0.084592 0.096454 0.163873 1.000000 0.077369
Wien 0.173311 0.314419 0.369341 0.131759 -0.017658 -0.094982 0.149637 0.077369 1.000000